package cn.com.infcn;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;

import cn.com.infcn.beanCondition.IsCreateTransportClient;

@SpringBootApplication
public class EduSearchApplication {

	@Value("${es_ip_port}")
	private String es_ip_port;
	@Bean
//	@Conditional(IsCreateTransportClient.class)
	public TransportClient transportClient() {
		System.err.println(es_ip_port);
		String[] ipPort=es_ip_port.split(",");
		TransportClient client=null;
		try {
			client = TransportClient.builder().build();
			for (String host : ipPort) {
				String[] split = host.split(":");
				client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(split[0]), Integer.parseInt(split[1])));
			}
			
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		return client;
	}
	public static void main(String[] args) {
		SpringApplication.run(EduSearchApplication.class, args);
	}
}
